package tests

import (
	"context"
	"fmt"
	"testing"

	"atomgit.com/openlinksaas/easy_trace/config"
	"github.com/google/uuid"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	v3 "skywalking.apache.org/repo/goapi/collect/language/agent/v3"
)

func TestSkywalking(t *testing.T) {
	conn, err := grpc.Dial(config.DEFAULT_SKYWALKING_GRPC_LISTEN_ADDR, grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		t.Error(err)
		return
	}
	client := v3.NewTraceSegmentReportServiceClient(conn)

	seg := &v3.SegmentCollection{
		Segments: []*v3.SegmentObject{
			{
				TraceId:        uuid.NewString(),
				TraceSegmentId: uuid.NewString(),
				Spans: []*v3.SpanObject{
					{
						SpanId:    1,
						StartTime: 0,
						EndTime:   10,
					},
				},
				Service:         "aa",
				ServiceInstance: "bb",
			},
		},
	}
	res, err := client.CollectInSync(context.Background(), seg)
	if err != nil {
		t.Error(err)
		return
	}
	fmt.Println(res)
}
